home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / user2grp.fr_ / user2grp.fr
Text File  |  1995-07-06  |  6KB  |  206 lines

  1. VERSION 4.00
  2. Begin VB.Form frmMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Add User to Group"
  5.    ClientHeight    =   2100
  6.    ClientLeft      =   1890
  7.    ClientTop       =   2055
  8.    ClientWidth     =   4770
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   2505
  19.    Left            =   1830
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   2100
  22.    ScaleWidth      =   4770
  23.    Top             =   1710
  24.    Width           =   4890
  25.    Begin VB.CommandButton cmdShowUsers 
  26.       Caption         =   "&Show Users"
  27.       Enabled         =   0   'False
  28.       Height          =   375
  29.       Left            =   3240
  30.       TabIndex        =   6
  31.       Top             =   600
  32.       Width           =   1215
  33.    End
  34.    Begin VB.ComboBox cboGroups 
  35.       Height          =   300
  36.       Left            =   960
  37.       Sorted          =   -1  'True
  38.       Style           =   2  'Dropdown List
  39.       TabIndex        =   4
  40.       Top             =   600
  41.       Width           =   2115
  42.    End
  43.    Begin VB.ComboBox cboUsers 
  44.       Height          =   300
  45.       Left            =   990
  46.       Sorted          =   -1  'True
  47.       Style           =   2  'Dropdown List
  48.       TabIndex        =   2
  49.       Top             =   120
  50.       Width           =   2115
  51.    End
  52.    Begin VB.CommandButton cmdClose 
  53.       Cancel          =   -1  'True
  54.       Caption         =   "Cl&ose"
  55.       Height          =   555
  56.       Left            =   2520
  57.       TabIndex        =   1
  58.       Top             =   1200
  59.       Width           =   1755
  60.    End
  61.    Begin VB.CommandButton cmdAddUser 
  62.       Caption         =   "&Add User"
  63.       Default         =   -1  'True
  64.       Enabled         =   0   'False
  65.       Height          =   555
  66.       Left            =   480
  67.       TabIndex        =   0
  68.       Top             =   1200
  69.       Width           =   1755
  70.    End
  71.    Begin VB.Label Label1 
  72.       Alignment       =   1  'Right Justify
  73.       AutoSize        =   -1  'True
  74.       BackColor       =   &H00C0C0C0&
  75.       Caption         =   "&Group"
  76.       Height          =   195
  77.       Left            =   180
  78.       TabIndex        =   5
  79.       Top             =   660
  80.       Width           =   525
  81.    End
  82.    Begin VB.Label Label2 
  83.       Alignment       =   1  'Right Justify
  84.       AutoSize        =   -1  'True
  85.       BackColor       =   &H00C0C0C0&
  86.       Caption         =   "&User:"
  87.       Height          =   195
  88.       Left            =   240
  89.       TabIndex        =   3
  90.       Top             =   180
  91.       Width           =   465
  92.    End
  93. End
  94. Attribute VB_Name = "frmMain"
  95. Attribute VB_Creatable = False
  96. Attribute VB_Exposed = False
  97. Option Explicit
  98.  
  99. #If Win32 Then
  100.     Private Declare Function GetWindowsDirectory Lib "kernel32" _
  101.         Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
  102.         ByVal nSize As Long) As Long
  103. #Else
  104.     Private Declare Function GetWindowsDirectory Lib "Kernel" _
  105.         (ByVal lpBuffer As String, _
  106.         ByVal nSize As Integer) As Integer
  107. #End If
  108.  
  109.  
  110.  
  111.  
  112. Private Sub cboGroups_Click()
  113.     cmdAddUser.Enabled = IIf(cboUsers.ListIndex = -1 Or cboGroups.ListIndex = -1, False, True)
  114.     cmdShowUsers.Enabled = IIf(cboGroups.ListIndex = -1, False, True)
  115. End Sub
  116. Private Sub cboUsers_Click()
  117.     cmdAddUser.Enabled = IIf(cboUsers.ListIndex = -1 Or cboGroups.ListIndex = -1, False, True)
  118. End Sub
  119.  
  120. Private Sub cmdShowUsers_Click()
  121.     frmUsers.Tag = cboGroups.TEXT
  122.     frmUsers.Show 1
  123. End Sub
  124.  
  125. Private Sub Form_Load()
  126.     Dim myUser As String, myPass As String
  127.     Dim winDir As String * 128
  128.     Dim dirLen As Integer
  129.     
  130.     ' On Error GoTo LoadError
  131.     ' Get the Windows directory and set the INI path.
  132.     dirLen = GetWindowsDirectory(winDir, 128)
  133.     If dirLen = 0 Then Error 32767
  134.     DBEngine.IniPath = Left$(winDir, dirLen) & "\VBDBHT.INI"
  135.     
  136.     ' Set the user and passwords for initial login.
  137.     myUser = "Admin"
  138.     myPass = "theboss"
  139.     DBEngine.DefaultUser = myUser
  140.     DBEngine.DefaultPassword = myPass
  141.     
  142.     FillUserList
  143.     FillGroupList
  144.  
  145. Exit Sub
  146. LoadError:
  147.     MsgBox Err & " " & Error$
  148. End
  149.  
  150. End Sub
  151.  
  152. Private Sub cmdAddUser_Click()
  153.     Dim newGroup As GROUP
  154.     Dim thePID As String
  155.     Dim usr As User
  156.     
  157.     On Error GoTo ChangeError
  158.     
  159.     ' If the user has not selected both a user and a group, generate an error
  160.     If cboUsers.ListIndex = -1 Then Error 32765
  161.     If cboGroups.ListIndex = -1 Then Error 32764
  162.     
  163.     ' Add the user to the designated group.
  164.     Set usr = DBEngine.Workspaces(0).Groups(cboGroups.TEXT).CreateUser(cboUsers.TEXT)
  165.     DBEngine.Workspaces(0).Groups(cboGroups.TEXT).Users.Append usr
  166.     
  167.     ' No errors, so must have been successful.
  168.     MsgBox "User " & cboUsers.TEXT & " added to " & cboGroups.TEXT, vbInformation
  169. Exit Sub
  170.  
  171. ChangeError:
  172.     Dim msg As String
  173.     Select Case Err.Number
  174.         Case 3032
  175.             msg = "User " & cboUsers.TEXT & " already belongs to Group " & cboGroups.TEXT
  176.         Case 32765
  177.             msg = "You have not selected a user."
  178.         Case 32764
  179.             msg = "You have not selected a group."
  180.         Case Else
  181.             msg = Err.Description
  182.     End Select
  183.     MsgBox msg, vbExclamation
  184. End Sub
  185.  
  186. Sub FillUserList()
  187.     Dim usr As User
  188.  
  189.     For Each usr In DBEngine.Workspaces(0).Users
  190.         If UCase$(usr.Name) <> "CREATOR" And UCase$(usr.Name) <> "ENGINE" Then
  191.             cboUsers.AddItem usr.Name
  192.         End If
  193.     Next
  194. End Sub
  195. Sub FillGroupList()
  196.     Dim grp As GROUP
  197.  
  198.     For Each grp In DBEngine.Workspaces(0).Groups
  199.         cboGroups.AddItem grp.Name
  200.     Next
  201. End Sub
  202. Private Sub cmdClose_Click()
  203.     End
  204. End Sub
  205.  
  206.